home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / tcpip / amiga / asrc29p.lha / tcptimer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  1.7 KB  |  70 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. int tcptimertype = 0;        /* default backoff to binary exponential */
  11. int Tcp_blimit = 31;
  12.  
  13. /* Timer timeout */
  14. void tcp_timeout(p)
  15. void *p;
  16. {
  17.     register struct tcb *tcb;
  18.  
  19.     tcb = p;
  20.     if(tcb == NULLTCB)
  21.         return;
  22.  
  23.     /* Make sure the timer has stopped (we might have been kicked) */
  24.     stop_timer(&tcb->timer);
  25.  
  26.     switch(tcb->state){
  27.     case TCP_TIME_WAIT:    /* 2MSL timer has expired */
  28.         close_self(tcb,NORMAL);
  29.         break;
  30.     default:        /* Retransmission timer has expired */
  31.         tcb->flags.retran = 1;    /* Indicate > 1  transmission */
  32.         tcb->backoff++;
  33.         if(Tcp_retry > 0)    /* From wnos4a9  -oz1dti */
  34.             if((tcb->backoff > Tcp_retry &&
  35.                  tcb->state != TCP_ESTABLISHED)
  36.                  || (tcb->backoff > Tcp_retry * 6
  37.                  && (tcb->state == TCP_ESTABLISHED ||
  38.                  tcb->state == TCP_FINWAIT1))) {
  39.                 close_self(tcb,TIMEOUT);
  40.                 break;
  41.             }
  42.         tcb->snd.ptr = tcb->snd.una;
  43.         /* Reduce slowstart threshold to half current window */
  44.         tcb->ssthresh = tcb->cwind / 2;
  45.         tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  46.         /* Shrink congestion window to 1 packet */
  47.         tcb->cwind = tcb->mss;
  48.         tcp_output(tcb);
  49.     }
  50. }
  51.  
  52. /* Backoff function - the subject of much research */
  53. int32 backoff(n)
  54. int n;
  55. {
  56.     if(tcptimertype) {    /* Linear */
  57.         if(n >= Tcp_blimit)        /* At backoff limit -- N1BEE */
  58.             n = Tcp_blimit;
  59.         else
  60.             ++n;
  61.         return (int32) n;     /* Linear backoff for sensible values! */
  62.     } else {        /* Binary exponential */
  63.         if(n > min(31,Tcp_blimit))
  64.             n = min(31,Tcp_blimit);
  65.                 /* Prevent truncation to zero */
  66.         return 1L << n;    /* Binary exponential back off */
  67.     }
  68. }
  69.  
  70.